//
//  SXRootRightViewController.m
//  ShiXun
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 张琪. All rights reserved.
//

#import "SXRootRightViewController.h"
#import "SXSlideViewController.h"
#import "AppDelegate.h"
#import "SXNewsRootViewController.h"
#import "SXReadRootViewController.h"
#import "SXTopicRootViewController.h"
#import "SXVideoRootViewController.h"

@interface SXRootRightViewController ()

@end

@implementation SXRootRightViewController

- (UIView *)topView
{
    if (!_topView) {
        _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 64)];
        _topView.backgroundColor = [UIColor colorWithRed:1.000 green:0.000 blue:0.012 alpha:1.000];
        
        UIImageView *nameImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 35, 25, 80, 30)];
        nameImageView.image = [UIImage imageNamed:@"shixun"];
        [_topView addSubview:nameImageView];
        
        [_topView addSubview:self.leftButton];
    }
    return _topView;
}

- (UIButton *)leftButton
{
    if (!_leftButton) {
        _leftButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _leftButton.frame = CGRectMake(10, 30, 20, 20);
        [_leftButton setBackgroundImage:[UIImage imageNamed:@"SX-chouti"] forState:(UIControlStateNormal)];
        SXSlideViewController *rootVC = [(AppDelegate *)[UIApplication sharedApplication].delegate rootVC];
        [_leftButton addTarget:rootVC action:@selector(openLeftView) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _leftButton;
}

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view addSubview:self.topView];
    self.view.backgroundColor = [UIColor whiteColor];
    
    SXNewsRootViewController *newsRootVC = [[SXNewsRootViewController alloc] init];
    newsRootVC.rootRightVC = self;
    UINavigationController *newsNC = [[UINavigationController alloc] initWithRootViewController:newsRootVC];
    newsNC.navigationBar.hidden = YES;
    newsNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"新闻" image:[[UIImage imageNamed:@"SX-xinwen"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] selectedImage:[[UIImage imageNamed:@"SX-xinwen_selected"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]];
    [newsNC.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    SXReadRootViewController *readRootVC = [[SXReadRootViewController alloc] init];
    readRootVC.rootRightVC = self;
    UINavigationController *readNC = [[UINavigationController alloc] initWithRootViewController:readRootVC];
    readNC.navigationBar.hidden = YES;
    readNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"阅读" image:[[UIImage imageNamed:@"SX-yuedu"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] selectedImage:[[UIImage imageNamed:@"SX-yuedu_selected"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]];
    [readNC.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    SXTopicRootViewController *topicRootVC = [[SXTopicRootViewController alloc] init];
    topicRootVC.rootRightVC = self;
    UINavigationController *topicNC = [[UINavigationController alloc] initWithRootViewController:topicRootVC];
    topicNC.navigationBar.hidden = YES;
    topicNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"话题" image:[[UIImage imageNamed:@"SX-huati"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] selectedImage:[[UIImage imageNamed:@"SX-huati_selected"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]];
    [topicNC.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    SXVideoRootViewController *videoRootVC = [[SXVideoRootViewController alloc] init];
    videoRootVC.rootRightVC = self;
    UINavigationController *videoNC = [[UINavigationController alloc] initWithRootViewController:videoRootVC];
    videoNC.navigationBar.hidden = YES;
    videoNC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"视听" image:[[UIImage imageNamed:@"SX-shipin"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] selectedImage:[[UIImage imageNamed:@"SX-shipin_selected"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]];
    [videoNC.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    self.viewControllers = @[newsNC, readNC, topicNC, videoNC];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
